package inet.db.tennis;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import inet.db.pool.*;
import inet.util.Logger;

public class TennisChampionDAO {

	private Logger logger = null;
	private DBPoolX poolX = null;
	public TennisChampionDAO(){
		logger = new Logger(this.getClass().getName());
		try{
			poolX = DBPoolX.getInstance(DBPoolXName.SERVICE_BONGDA);
		}catch(Exception exception){
			logger.log(exception.toString()); 
		}
	}
	
	/**
	 * function get a TennisChampion by id
	 * @param id
	 * @return
	 */
    public TennisChampion getRow(BigDecimal id) {
        Connection conn = null;
        PreparedStatement preStmt = null;
        ResultSet rs = null;
        String strSQL = null;
        TennisChampion champion = null;
        try {
            conn = poolX.getConnection();
            strSQL =
                " select a.ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
                " CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, a.LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
                " from TENNIS_CHAMPION a left join TENNIS_COUNTRY b on a.COUNTRY_ID = b.ID where a.ID = ? ";
            preStmt = conn.prepareStatement(strSQL);
            preStmt.setBigDecimal(1, id);
            rs = preStmt.executeQuery();
            if (rs.next()) {
            	champion = new TennisChampion();
            	champion.setId(rs.getBigDecimal(1));
            	champion.setCode(rs.getString(2));
            	champion.setName(rs.getString(3));
            	champion.setCateId(rs.getBigDecimal(4));
            	champion.setCourtType(rs.getInt(5));
            	champion.setPoint(rs.getInt(6));
            	champion.setBonusMoney(rs.getString(7));
            	champion.setCountryId(rs.getBigDecimal(8));
            	champion.setCurrentPhase(rs.getBigDecimal(9));
            	champion.setCurrentRound(rs.getString(10));
            	champion.setCurrentSeason(rs.getBigDecimal(11));
            	champion.setTotalSet(rs.getInt(12));
            	champion.setStatus(rs.getInt(13));
            	champion.setLastUpdated(rs.getTimestamp(14));
            	champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
            }
        }
        catch (SQLException e) {
            logger.error("getRow: Error executing SQL " + strSQL + ">>>" + e.toString());
        } finally {
            poolX.releaseConnection(conn, preStmt, rs);
        }
        return champion;
    }
    
    /**
     * function get a TennisChampion by championCode
     * @param championCode
     * @return TennisChampion
     */
    public TennisChampion getRow(String championCode) {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select a.ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
    			" CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, a.LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
    			" from TENNIS_CHAMPION a left join TENNIS_COUNTRY b on a.COUNTRY_ID = b.ID where CODE = ? ";
    		preStmt = conn.prepareStatement(strSQL);
    		preStmt.setString(1, championCode);
    		rs = preStmt.executeQuery();
    		if (rs.next()) {
    			champion = new TennisChampion();
    			champion.setId(rs.getBigDecimal(1));
    			champion.setCode(rs.getString(2));
    			champion.setName(rs.getString(3));
    			champion.setCateId(rs.getBigDecimal(4));
    			champion.setCourtType(rs.getInt(5));
    			champion.setPoint(rs.getInt(6));
    			champion.setBonusMoney(rs.getString(7));
    			champion.setCountryId(rs.getBigDecimal(8));
    			champion.setCurrentPhase(rs.getBigDecimal(9));
    			champion.setCurrentRound(rs.getString(10));
    			champion.setCurrentSeason(rs.getBigDecimal(11));
    			champion.setTotalSet(rs.getInt(12));
    			champion.setStatus(rs.getInt(13));
    			champion.setLastUpdated(rs.getTimestamp(14));
    			champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
    		}
    	}
    	catch (SQLException e) {
    		logger.error("getRow: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return champion;
    }
    
    /**
     * function check existed champion code
     * @param championCode
     * @return return true if champion code existed else return false.
     */
    public boolean isExistedChampionCode(String championCode) {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	boolean result = false;
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select ID from TENNIS_CHAMPION where CODE = ? ";
    		preStmt = conn.prepareStatement(strSQL);
    		preStmt.setString(1, championCode);
    		rs = preStmt.executeQuery();
    		if (rs.next()) {
    			result = true;
    		}
    	}
    	catch (SQLException e) {
    		logger.error("isExistedChampionCode: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return result;
    }
    
    /**
     * fucntion get all champion
     * @return Vector<TennisCountry> 
     * TennisChampion
     */
    public Vector<TennisChampion> findAll() {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	Vector<TennisChampion> vChampion = null;
    	
    	try {
    		conn = poolX.getConnection();
    		strSQL =
                " select a.ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
                " CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, a.LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
                " from TENNIS_CHAMPION a left join TENNIS_COUNTRY b on a.COUNTRY_ID = b.ID ";
    		preStmt = conn.prepareStatement(strSQL);
    		rs = preStmt.executeQuery();
    		vChampion = new Vector<TennisChampion>();
    		while (rs.next()) {
    			champion = new TennisChampion();
            	champion.setId(rs.getBigDecimal(1));
            	champion.setCode(rs.getString(2));
            	champion.setName(rs.getString(3));
            	champion.setCateId(rs.getBigDecimal(4));
            	champion.setCourtType(rs.getInt(5));
            	champion.setPoint(rs.getInt(6));
            	champion.setBonusMoney(rs.getString(7));
            	champion.setCountryId(rs.getBigDecimal(8));
            	champion.setCurrentPhase(rs.getBigDecimal(9));
            	champion.setCurrentRound(rs.getString(10));
            	champion.setCurrentSeason(rs.getBigDecimal(11));
            	champion.setTotalSet(rs.getInt(12));
            	champion.setStatus(rs.getInt(13));
            	champion.setLastUpdated(rs.getTimestamp(14));
            	champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
            	
            	vChampion.addElement(champion);
    		}
    	}
    	catch (SQLException e) {
    		logger.error("findAll: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return vChampion;
    }
    
    /**
     * function find TennisChampion by Status
     * @param status 
     * @return Vector<TennisChampion>
     */
    public Vector<TennisChampion> findByStatus(int status) {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	Vector<TennisChampion> vChampion = null;
    	
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select a.ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
    			" CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, a.LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
    			" from TENNIS_CHAMPION a left join TENNIS_COUNTRY b on a.COUNTRY_ID = b.ID where STATUS = ? ";
    		preStmt = conn.prepareStatement(strSQL);
    		preStmt.setInt(1, status);
    		
    		rs = preStmt.executeQuery();
    		vChampion = new Vector<TennisChampion>();
    		while (rs.next()) {
    			champion = new TennisChampion();
    			champion.setId(rs.getBigDecimal(1));
    			champion.setCode(rs.getString(2));
    			champion.setName(rs.getString(3));
    			champion.setCateId(rs.getBigDecimal(4));
    			champion.setCourtType(rs.getInt(5));
    			champion.setPoint(rs.getInt(6));
    			champion.setBonusMoney(rs.getString(7));
    			champion.setCountryId(rs.getBigDecimal(8));
    			champion.setCurrentPhase(rs.getBigDecimal(9));
    			champion.setCurrentRound(rs.getString(10));
    			champion.setCurrentSeason(rs.getBigDecimal(11));
    			champion.setTotalSet(rs.getInt(12));
    			champion.setStatus(rs.getInt(13));
    			champion.setLastUpdated(rs.getTimestamp(14));
    			champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
    			
    			vChampion.addElement(champion);
    		}
    	}
    	catch (SQLException e) {
    		logger.error("findAll: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return vChampion;
    }
    
    /**
     * function find all TennisChampion (STATUS = WAITING, RUNNING, FINAL) has STATUS <> STOP (3).
     * @return Vector<TennisChampion>
     */
    public Vector<TennisChampion> findChampionRunning() {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	Vector<TennisChampion> vChampion = null;
    	
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select a.ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
    			" CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, a.LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
    			" from TENNIS_CHAMPION a left join TENNIS_COUNTRY b on a.COUNTRY_ID = b.ID " +
    			" where STATUS <> " + TennisConst.TENNIS_CHAMPION_STOP;
    		preStmt = conn.prepareStatement(strSQL);
    		
    		rs = preStmt.executeQuery();
    		vChampion = new Vector<TennisChampion>();
    		while (rs.next()) {
    			champion = new TennisChampion();
    			champion.setId(rs.getBigDecimal(1));
    			champion.setCode(rs.getString(2));
    			champion.setName(rs.getString(3));
    			champion.setCateId(rs.getBigDecimal(4));
    			champion.setCourtType(rs.getInt(5));
    			champion.setPoint(rs.getInt(6));
    			champion.setBonusMoney(rs.getString(7));
    			champion.setCountryId(rs.getBigDecimal(8));
    			champion.setCurrentPhase(rs.getBigDecimal(9));
    			champion.setCurrentRound(rs.getString(10));
    			champion.setCurrentSeason(rs.getBigDecimal(11));
    			champion.setTotalSet(rs.getInt(12));
    			champion.setStatus(rs.getInt(13));
    			champion.setLastUpdated(rs.getTimestamp(14));
    			champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
            	
    			vChampion.addElement(champion);
    		}
    	}
    	catch (SQLException e) {
    		logger.error("findAll: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return vChampion;
    }
    
    /**
     * function insert a TennisChampion
     * @param championCode
     * @param name
     * @param cateId
     * @param courtType
     * @param countryId
     * @param totalSet
     * @param status
     * @param level
     * @param hasBracket
     * @return true if insert success else return false.
     */
	public boolean insertRow(String championCode, String name, BigDecimal cateId, int courtType, BigDecimal countryId, int totalSet, int status, int level, int hasBracket){
		Connection conn = null;
        PreparedStatement preStmt = null;
        boolean result = false;
        String strSQL = null;
        try {
            conn = poolX.getConnection();

        	strSQL =" insert into TENNIS_CHAMPION( ID, CODE, CODE_SMS, NAME, CATE_ID, COURT_TYPE, COUNTRY_ID, TOTAL_SET, STATUS, CHAMPION_LEVEL, HAS_BRACKET, LAST_UPDATED ) " +
    				" values(TENNIS_CHAMPION_SEQ.nextval, TENNIS_CHAMPION_SEQ.currval, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ";
	        preStmt = conn.prepareStatement(strSQL);
	        preStmt.setString(1, championCode);
	        preStmt.setString(2, name);
	        preStmt.setBigDecimal(3, cateId);
	        preStmt.setInt(4, courtType);
	        preStmt.setBigDecimal(5, countryId);
	        preStmt.setInt(6, totalSet);
	        preStmt.setInt(7, status);
	        preStmt.setInt(8, level);
	        preStmt.setInt(9, hasBracket);
	        
	        if (preStmt.executeUpdate()>=1) {
	        	result = true;
	        }
        } catch (Exception ex) {
        	logger.error("insertRow: Error executing SQL " + strSQL + ">>>" + ex.toString());
        } finally {
        	poolX.releaseConnection(conn, preStmt);
       }
       return result;
	}
	
	/**
	 * function update TennisChampion
	 * @param id
	 * @param championCode
	 * @param name
	 * @param cateId
	 * @param courtType
	 * @param countryId
	 * @param totalSet
	 * @param currentPhase
	 * @param currentRound
	 * @param currentSeason
	 * @param status
	 * @param level
	 * @param hasBracket
	 * @return true if update success else return false.
	 */
	public boolean updateRow(BigDecimal id, String championCode, String name, BigDecimal cateId, int courtType, BigDecimal countryId, 
				int totalSet, BigDecimal currentPhase, String currentRound, BigDecimal currentSeason, int status, int level, int hasBracket){
		Connection conn = null;
        PreparedStatement preStmt = null;
        boolean result = false;
        String strSQL = null;
        try {
        	conn = poolX.getConnection();
        	strSQL =" update TENNIS_CHAMPION set CODE_SMS = ?, NAME = ?, CATE_ID = ?, COURT_TYPE = ?, COUNTRY_ID = ?, TOTAL_SET = ?, CURRENT_PHASE = ?, " +
        			" CURRENT_ROUND = ?, CURRENT_SEASON = ?, STATUS = ?, CHAMPION_LEVEL = ?, HAS_BRACKET = ?, LAST_UPDATED = sysdate " +
        			" where ID = ?";
        	preStmt = conn.prepareStatement(strSQL);
        	preStmt.setString(1, championCode);
	        preStmt.setString(2, name);
	        preStmt.setBigDecimal(3, cateId);
	        preStmt.setInt(4, courtType);
	        preStmt.setBigDecimal(5, countryId);
	        preStmt.setInt(6, totalSet);
	        preStmt.setBigDecimal(7, currentPhase);
	        preStmt.setString(8, currentRound);
	        preStmt.setBigDecimal(9, currentSeason);
	        preStmt.setInt(10, status);
	        preStmt.setInt(11, level);
	        preStmt.setInt(12, hasBracket);
	        
        	preStmt.setBigDecimal(13, id);
        	
        	if(preStmt.executeUpdate() > 0){
        		result = true;
        	}
        } catch (Exception ex) {
        	logger.error("updateRow: Error executing SQL " + strSQL + ">>>" + ex.toString());
        } finally {
        	poolX.releaseConnection(conn, preStmt);
       }
        return result;
	}
	
	/**
	 * function update TennisChampion
	 * @param id
	 * @param championCode
	 * @param name
	 * @param cateId
	 * @param courtType
	 * @param countryId
	 * @param totalSet
	 * @param currentPhase
	 * @param currentRound
	 * @param currentSeason
	 * @param status
	 * @param level
	 * @param point
	 * @param bonusMoney
	 * @param hasBracket
	 * @return true if update success else return false.
	 */
	public boolean updateRow(BigDecimal id, String championCode, String name, BigDecimal cateId, int courtType, BigDecimal countryId, 
			int totalSet, BigDecimal currentPhase, String currentRound, BigDecimal currentSeason, int status, int level, int point, String bonusMoney, int hasBracket){
		Connection conn = null;
		PreparedStatement preStmt = null;
		boolean result = false;
		String strSQL = null;
		try {
			conn = poolX.getConnection();
			strSQL =" update TENNIS_CHAMPION set CODE_SMS = ?, NAME = ?, CATE_ID = ?, COURT_TYPE = ?, COUNTRY_ID = ?, TOTAL_SET = ?, CURRENT_PHASE = ?, " +
			" CURRENT_ROUND = ?, CURRENT_SEASON = ?, STATUS = ?, CHAMPION_LEVEL = ?, POINT = ?, BONUS_MONEY = ?, HAS_BRACKET = ?, LAST_UPDATED = sysdate " +
			" where ID = ?";
			preStmt = conn.prepareStatement(strSQL);
			preStmt.setString(1, championCode);
			preStmt.setString(2, name);
			preStmt.setBigDecimal(3, cateId);
			preStmt.setInt(4, courtType);
			preStmt.setBigDecimal(5, countryId);
			preStmt.setInt(6, totalSet);
			preStmt.setBigDecimal(7, currentPhase);
			preStmt.setString(8, currentRound);
			preStmt.setBigDecimal(9, currentSeason);
			preStmt.setInt(10, status);
			preStmt.setInt(11, level);
			preStmt.setInt(12, point);
			preStmt.setString(13, bonusMoney);
			preStmt.setInt(14, hasBracket);
			
			preStmt.setBigDecimal(15, id);
			
			if(preStmt.executeUpdate() > 0){
				result = true;
			}
		} catch (Exception ex) {
			logger.error("updateRow: Error executing SQL " + strSQL + ">>>" + ex.toString());
		} finally {
			poolX.releaseConnection(conn, preStmt);
		}
		return result;
	}
	
	/**
	 * function update status of champion by id
	 * @param id
	 * @param status
	 * @return true if update success else return false.
	 */
	public boolean updateStatus(BigDecimal id, int status){
		Connection conn = null;
		PreparedStatement preStmt = null;
		boolean result = false;
		String strSQL = null;
		try {
			conn = poolX.getConnection();
			strSQL =" update TENNIS_CHAMPION set STATUS = ?, LAST_UPDATED = sysdate where ID = ?";
			preStmt = conn.prepareStatement(strSQL);
			preStmt.setInt(1, status);
			
			preStmt.setBigDecimal(2, id);
			
			if(preStmt.executeUpdate() > 0){
				result = true;
			}
		} catch (Exception ex) {
			logger.error("updateStatus: Error executing SQL " + strSQL + ">>>" + ex.toString());
		} finally {
			poolX.releaseConnection(conn, preStmt);
		}
		return result;
	}
	
	/**
	 * function update champion status by CODE
	 * @param championCode
	 * @param status
	 * @return true if update success else return false.
	 */
	public boolean updateStatus(String championCode, int status){
		Connection conn = null;
		PreparedStatement preStmt = null;
		boolean result = false;
		String strSQL = null;
		try {
			conn = poolX.getConnection();
			strSQL =" update TENNIS_CHAMPION set STATUS = ?, LAST_UPDATED = sysdate where CODE = ?";
			preStmt = conn.prepareStatement(strSQL);
			preStmt.setInt(1, status);
			preStmt.setString(2, championCode);
			
			if(preStmt.executeUpdate() > 0){
				result = true;
			}
		} catch (Exception ex) {
			logger.error("updateStatus: Error executing SQL " + strSQL + ">>>" + ex.toString());
		} finally {
			poolX.releaseConnection(conn, preStmt);
		}
		return result;
	}

	/**
	 * function delete a TennisChampion
	 * @param id
	 * @return true if delete success else return false.
	 */
	public boolean deleteRow(BigDecimal id){
		Connection conn = null;
		PreparedStatement preStmt = null;
		boolean result = false;
		String strSQL = null;
		try {
			conn = poolX.getConnection();
			strSQL =" delete from TENNIS_CHAMPION where ID = ? ";
			preStmt = conn.prepareStatement(strSQL);
			preStmt.setBigDecimal(1, id);
			if(preStmt.executeUpdate() > 0){
				result = true;
			}
		} catch (Exception ex) {
			logger.error("deleteRow: Error executing SQL " + strSQL + ">>>" + ex.toString());
		} finally {
			poolX.releaseConnection(conn, preStmt);
		}
		return result;
	}
	
	
	/**
     * function find TennisChampion by code
     * @param status 
     * @return Vector<TennisChampion>
     * Author : Hoannd
     */
    public Vector<TennisChampion> findByChampionCode(String code) {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	Vector<TennisChampion> vChampion = null;
    	
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
    			" CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET, STATUS, LAST_UPDATED, CHAMPION_LEVEL, COUNTRY_NAME, HAS_BRACKET, CODE_SMS " +
    			" from TENNIS_CHAMPION   where lower(CODE) = ? ";
    		preStmt = conn.prepareStatement(strSQL);
    		preStmt.setString(1, code);
    		
    		rs = preStmt.executeQuery();
    		vChampion = new Vector<TennisChampion>();
    		while (rs.next()) {
    			champion = new TennisChampion();
    			champion.setId(rs.getBigDecimal(1));
    			champion.setCode(rs.getString(2));
    			champion.setName(rs.getString(3));
    			champion.setCateId(rs.getBigDecimal(4));
    			champion.setCourtType(rs.getInt(5));
    			champion.setPoint(rs.getInt(6));
    			champion.setBonusMoney(rs.getString(7));
    			champion.setCountryId(rs.getBigDecimal(8));
    			champion.setCurrentPhase(rs.getBigDecimal(9));
    			champion.setCurrentRound(rs.getString(10));
    			champion.setCurrentSeason(rs.getBigDecimal(11));
    			champion.setTotalSet(rs.getInt(12));
    			champion.setStatus(rs.getInt(13));
    			champion.setLastUpdated(rs.getTimestamp(14));
    			champion.setLevel(rs.getInt(15));
            	champion.setCountryName(rs.getString(16));
            	champion.setHasBracket(rs.getInt(17));
            	champion.setCodeSMS(rs.getString(18));
    			
    			vChampion.addElement(champion);
    		}
    	}
    	catch (SQLException e) {
    		logger.error("findAll: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return vChampion;
    }
    
    public Vector<TennisChampion> getCurrentPhasedRound(String code) {
    	Connection conn = null;
    	PreparedStatement preStmt = null;
    	ResultSet rs = null;
    	String strSQL = null;
    	TennisChampion champion = null;
    	Vector<TennisChampion> vChampion = null;
    	
    	try {
    		conn = poolX.getConnection();
    		strSQL =
    			" select ID, CODE, NAME, CATE_ID, COURT_TYPE, POINT, BONUS_MONEY, COUNTRY_ID, CURRENT_PHASE, " +
    			" CURRENT_ROUND, CURRENT_SEASON, TOTAL_SET "+
    			" from TENNIS_CHAMPION   where lower(CODE) = ? and CURRENT_PHASE<>0 and CURRENT_ROUND is not null";
    		preStmt = conn.prepareStatement(strSQL);
    		preStmt.setString(1, code);
    		
    		rs = preStmt.executeQuery();
    		vChampion = new Vector<TennisChampion>();
    		while (rs.next()) {
    			champion = new TennisChampion();
    			champion.setId(rs.getBigDecimal(1));
    			champion.setCode(rs.getString(2));
    			champion.setName(rs.getString(3));
    			champion.setCateId(rs.getBigDecimal(4));
    			champion.setCourtType(rs.getInt(5));
    			champion.setPoint(rs.getInt(6));
    			champion.setBonusMoney(rs.getString(7));
    			champion.setCountryId(rs.getBigDecimal(8));
    			champion.setCurrentPhase(rs.getBigDecimal(9));
    			champion.setCurrentRound(rs.getString(10));
    			champion.setCurrentSeason(rs.getBigDecimal(11));
    			champion.setTotalSet(rs.getInt(12));
    			
    			vChampion.addElement(champion);
    		}
    	}
    	catch (SQLException e) {
    		logger.error("findAll: Error executing SQL " + strSQL + ">>>" + e.toString());
    	} finally {
    		poolX.releaseConnection(conn, preStmt, rs);
    	}
    	return vChampion;
    }
    
    
}
